package ${package}.service.impl;

import ${package}.entity.${entityClassName};
import ${package}.vo.${voClassName};
import ${package}.service.${serviceClassName};
import ${package}.dao.${daoClassName};
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

/**
<#if config.commentConfig.isAddFunctionComment == true>
 * 	${table.tableName}（${table.tableComment}）的service层实现
 </#if>
<#if config.commentConfig.isAddAuthorComment == true>
 *	@author ${author}
</#if>
<#if config.commentConfig.isAddDateComment == true>
 *	@Date ${date}
</#if>
 */
@Service
public class ${serviceClassName}Impl implements ${serviceClassName}{

	@Autowired
	private ${daoClassName} ${daoClassName?uncap_first};


<#if config.daoJavaConfig.isCreateCountMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据查询条件，判断记录是否存在
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return true -- 存在记录<br>
 	 *			false - 不存在
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public boolean isExistQuery(${voClassName} query){
		if(query == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		int resultNum = ${daoClassName?uncap_first}.${config.daoJavaConfig.countMethodName}(query);
		return resultNum > 0;
	}
</#if>


<#if config.daoJavaConfig.isCreateGetOneByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键判断是否存在
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 记录主键
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return true -- 存在记录<br>
 	 *			false - 不存在
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public boolean isExistById(${table.primaryKey.javaType} id){
		if(id == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		${entityClassName} result = ${daoClassName?uncap_first}.${config.daoJavaConfig.getOneByIdMethodName}(id);
		return result != null;
	}
</#if>
	
	
	
<#if config.daoJavaConfig.isCreateCountMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，获取数量
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 符合条件的记录数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public int ${config.daoJavaConfig.countMethodName}(${voClassName} query){
		if(query == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.countMethodName}(query);
	}
</#if>
	
	
	
<#if config.daoJavaConfig.isCreateGetAllMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，获取全部
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
  	 *	@return List<${entityClassName}> 符合条件的记录
  	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public List<${entityClassName}> ${config.daoJavaConfig.getAllMethodName}(${voClassName} query){
		if(query == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.getAllMethodName}(query);
	}
</#if>




<#if config.daoJavaConfig.isCreateGetAllPageMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，分页获取
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 *	@param pageNum 页数
 	 *	@param pageSize 页面大小
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return List<${entityClassName}> 符合条件的记录，分页
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public List<${entityClassName}> ${config.daoJavaConfig.getAllPageMethodName}(${voClassName} query,Integer pageNum,Integer pageSize){
		if(query == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		if(pageNum == null){
			pageNum = 1;
		}
		if(pageSize == null){
			pageSize = 10;
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.getAllPageMethodName}(query,pageNum,pageSize);
	}
</#if>
	
	
	

<#if config.daoJavaConfig.isCreateGetOneByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键id获取
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 主键id
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return ${entityClassName} 符合条件的记录
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	public ${entityClassName} ${config.daoJavaConfig.getOneByIdMethodName}(${table.primaryKey.javaType} id){
		if(id == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.getOneByIdMethodName}(id);
	}
</#if>
	
	
	
<#if config.daoJavaConfig.isCreateDeleteByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键id删除记录
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 主键id
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 删除的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	@Transactional
	public int ${config.daoJavaConfig.deleteByIdMethodName}(${table.primaryKey.javaType} id){
		if(id == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.deleteByIdMethodName}(id);
	}
</#if>
	
	
	
<#if config.daoJavaConfig.isCreateInsertNotNullFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	非空字段插入
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 插入的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	@Transactional
	public int ${config.daoJavaConfig.insertNotNullFieldMethodName}(${entityClassName} entity){
		if(entity == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.insertNotNullFieldMethodName}(entity);
	}
</#if>




<#if config.daoJavaConfig.isCreateInsertAllFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	全字段插入
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 插入的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	@Transactional
	public int ${config.daoJavaConfig.insertAllFieldMethodName}(${entityClassName} entity){
		if(entity == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.insertAllFieldMethodName}(entity);
	}
</#if>





<#if config.daoJavaConfig.isCreateUpdateNotNullFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键，非空字段更新，主键不更新
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 更新的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	@Transactional
	public int ${config.daoJavaConfig.updateNotNullFieldMethodName}(${entityClassName} entity){
		if(entity == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.updateNotNullFieldMethodName}(entity);
	}
</#if>




<#if config.daoJavaConfig.isCreateUpdateAllFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键，全字段更新，主键不更新
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
     <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 更新的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	 </#if>
	  <#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
 	</#if>
     */
	@Override
	@Transactional
	public int ${config.daoJavaConfig.updateAllFieldMethodName}(${entityClassName} entity){
		if(entity == null){
			throw new IllegalArgumentException("参数不能为null");
		}
		return ${daoClassName?uncap_first}.${config.daoJavaConfig.updateAllFieldMethodName}(entity);
	}
</#if>
}
